package com.project.service;

import com.project.bean.UserBean;
import com.project.dao.IUserDao;
import com.project.dao.impl.UserDaoImpl;
import com.project.server.Request;
import com.project.server.Response;
import com.project.server.Servlet;
import com.project.util.DaoFactory;
import com.project.util.WebServlet;

import java.time.LocalDate;

/**
 * 添加用户组件
 */
@WebServlet("add")
public class AddService implements Servlet {
    private IUserDao dao = (IUserDao) DaoFactory.getDao("IUserDao");
    public void service(Request req, Response resp){
        //将表单数据封装成用户对象
        UserBean user = new UserBean();
        user.setName(req.getParameter("userName"));
        user.setPassword(req.getParameter("password"));
        user.setBirthday(LocalDate.parse(req.getParameter("birthday")));
        //调用持久方法，完成添加
        dao.add(user);
        FindAllService find = new FindAllService();
        find.service(req,resp);
    }
}
